﻿using Microsoft.SharePoint.Administration;
using SP.FeatureAdministrationTool.Extensions;
using System.Collections.Generic;

namespace SP.FeatureAdministrationTool.WebApplicationModule
{
    public class WebApplicationManager
    {
        public static List<WebApplication> GetAllApplications()
        {
            List<WebApplication> allWebApps = new List<WebApplication>();
            foreach (SPWebApplication webApp in SPFarm.Local.GetAllWebApplications())
            {
                allWebApps.Add(new WebApplication()
                {
                    Id = webApp.Id,
                    DisplayName = string.IsNullOrEmpty(webApp.DisplayName) ? webApp.ApplicationPool.Name : webApp.DisplayName
                });
            }

            return allWebApps;
        }
    }
}
